<?php

namespace test;


use Php\Queue\Query;
use Swoole\Coroutine\System;

class Test
{
	public function job(Query $query, $data)
	{
		echo '进入job', PHP_EOL;
		$num = random_int(1, 3);
		// 模拟io
		if (extension_loaded('swoole')) {
			System::sleep($num);
		} else {
			sleep($num);
		}
		
		echo $data['messageId'], '-----pid:', getmypid(),'---等待了--',$num, PHP_EOL;
		$query->success($data['messageId']);
	}
	
	function randFloat($min = 0, $max = 1): float
	{
		$rand = $min + mt_rand() / mt_getrandmax() * ($max - $min);
		return floatval(number_format($rand, 2));
	}
}